/*
 * Sii Core Base Application
 *
 * Copyright (c) 2011 Sii Sp. z o.o. All rights reserved.
 */
package com.gdziarmaga.webshop.utils.filtering;

import org.hibernate.criterion.MatchMode;

public class FilterMatchModeConverter {

    /**
     * Converts {@link MatchMode} to {@link FilterMatchMode}.
     * @param matchMode - provided {@link MatchMode} instance
     * @return <tt>FilterMatchMode</tt> corresponding given <tt>MatchMode</tt>
     */
    public static FilterMatchMode convertToFilterMatchMode(MatchMode matchMode) {
        if (MatchMode.ANYWHERE.equals(matchMode)) {
            return FilterMatchMode.ANYWHERE;
        } else if (MatchMode.EXACT.equals(matchMode)) {
            return FilterMatchMode.EXACT;
        } else if (MatchMode.START.equals(matchMode)) {
            return FilterMatchMode.START;
        } else if (MatchMode.END.equals(matchMode)) {
            return FilterMatchMode.END;
        }
        return FilterMatchMode.ANYWHERE;
    }

    /**
     * Converts {@link FilterMatchMode} to {@link MatchMode}.
     * @param filterMatchMode - provided {@link FilterMatchMode} instance
     * @return <tt>MatchMode</tt> corresponding given <tt>FilterMatchMode</tt>
     */
    public static MatchMode convertToMatchMode(FilterMatchMode filterMatchMode) {
        switch (filterMatchMode) {
        case ANYWHERE:
            return MatchMode.ANYWHERE;
        case EXACT:
            return MatchMode.EXACT;
        case START:
            return MatchMode.START;
        case END:
            return MatchMode.END;
        default:
            return MatchMode.ANYWHERE;
        }
    }

}
